//
//  NewFeatureCollectionViewController.swift
//  01-微博项目搭建
//
//  Created by Adolph on 15/5/17.
//  Copyright (c) 2015年 Adolph. All rights reserved.
//

import UIKit



class NewFeatureCollectionViewController: UICollectionViewController {
   
    @IBOutlet weak var layout: UICollectionViewFlowLayout!
    
    /// 图片总数
    let imageCount = 4
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
// 提示：在不同的控制器中，具体设置布局属性前，一定记住跟踪几个生命周期函数
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        layout.itemSize = view.bounds.size
        NSNotificationCenter.defaultCenter().postNotificationName(showMainNotification, object: "Main")
    }
   
    // MARK: UICollectionViewDataSource

    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        //#warning Incomplete method implementation -- Return the number of items in the section
        return self.imageCount
    }

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("NewFeatureCell", forIndexPath: indexPath) as! NewFeatureCollectionCell
       cell.setImageWithIndex(indexPath.item)
    
        return cell
    }
  
    override func collectionView(collectionView: UICollectionView, didEndDisplayingCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
        // 获取正在显示的cell
        println(collectionView.indexPathsForVisibleItems())
        let path = collectionView.indexPathsForVisibleItems().last as! NSIndexPath
        
        if path.item == imageCount - 1 {
          let cell = collectionView.cellForItemAtIndexPath(path) as! NewFeatureCollectionCell
         cell.showStartButton()
        }
    }
}
